package flyweight;

import java.util.HashMap;

/**
 * @Author: Ma JiBin
 * @Email: 1423553596@qq.com
 * @Date: 2018/9/10 10:40
 * @Description: 图形工厂类
 */
public class ShapeFactory {
    private static final HashMap<String, Shape> cicleMap = new HashMap<>();

    /**
     * 获取圆形类方法
     *
     * @param color 颜色
     * @return 该颜色Circle对象
     */
    public static Shape getCircle(String color) {
        Circle circle = (Circle) cicleMap.get(color);

        if (circle == null) {
            circle = new Circle(color);
            cicleMap.put(color, circle);
            System.out.println("Creating circle of color : " + color);
        }
        return circle;
    }
}
